

class Student{
    public String name;
    public int age;
    public static String className;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
//        System.out.println("构造方法");
    }

    {
        this.name = "小红";
        this.age = 20;
//        System.out.println("实例代码块");
    }

    static {
        className = "一班";
//        System.out.println("静态代码块");
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public void print(){
        System.out.println("我叫" + name);
    }
}

public class Text {
    public static void main(String[] args) {
        Student stu = new Student("小明",18);
        System.out.println(stu);
        System.out.println(stu.toString());
    }
}









